var pathName = window.document.location.pathname;
var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);

/**
 * 获取二级渠道
 */
function initTwo(provinceID) {
	$("#channelTwo option").remove();
	$("#channelTwo").append("<option value='0'>请选择</option>");
	$("#channelTwoShort").val("无");

	$("#channelThree option").remove();
	$("#channelThree").append("<option value='0'>请选择</option>");
	$("#channelThreeShort").val("无");

	$("#channelFour option").remove();
	$("#channelFour").append("<option value='0'>请选择</option>");
	$("#channelFourShort").val("无");

	$("#channelFive option").remove();
	$("#channelFive").append("<option value='0'>请选择</option>");
	$("#channelFiveShort").val("无");
	$("#linkSite").val("无");
	$("#downloadLink").val("无");

	getButton("channelTwo", "channelOneShort", provinceID);

}
/**
 * 获取三级渠道
 */
function initThree(provinceID) {
	$("#channelThree option").remove();
	$("#channelThree").append("<option value='0'>请选择</option>");
	$("#channelThreeShort").val("无");

	$("#channelFour option").remove();
	$("#channelFour").append("<option value='0'>请选择</option>");
	$("#channelFourShort").val("无");

	$("#channelFive option").remove();
	$("#channelFive").append("<option value='0'>请选择</option>");
	$("#channelFiveShort").val("无");
	$("#linkSite").val("无");
	$("#downloadLink").val("无");

	getButton("channelThree", "channelTwoShort", provinceID);
}
/**
 * 获取四级渠道
 */
function initFour(provinceID) {
	$("#channelFour option").remove();
	$("#channelFour").append("<option value='0'>请选择</option>");
	$("#channelFourShort").val("无");

	$("#channelFive option").remove();
	$("#channelFive").append("<option value='0'>请选择</option>");
	$("#channelFiveShort").val("无");
	$("#linkSite").val("无");
	$("#downloadLink").val("无");

	getButton("channelFour", "channelThreeShort", provinceID);

}
/**
 * 获取五级渠道
 */
function initFive(provinceID) {
	$("#channelFive option").remove();
	$("#channelFive").append("<option value='0'>请选择</option>");
	getButton("channelFive", "channelFourShort", provinceID);

}
function initwu(provinceID) {
	$.ajax({
		type : "POST",
		url : projectName + "/channel/selectAbb.do?key=" + provinceID,
		success : function(datas) {
			datas = JSON.parse(datas);
			if (datas != null) {
				$("#channelFiveShort").val(datas[0].generalizeAbbreviation);
				$("#linkSite").val(datas[0].linkSite);
				$("#downloadLink").val(datas[0].channelnumber);
			}
		}
	});
	$("#ycwbk").val(provinceID);
}

function getButton(channel, channelShort, provinceID) {
	$.ajax({
		type : "POST",
		url : projectName + "/channel/selectLower.do?key=" + provinceID,
		success : function(data) {
			data = JSON.parse(data);
			$.each(data, function(i, it) {
				$("#" + channel).append(
						"<option value='" + it.generalizeId + "'>"
								+ it.channelname + "</option>");
			});
		}
	});
	$.ajax({
		type : "POST",
		url : projectName + "/channel/selectAbb.do?key=" + provinceID,
		success : function(datas) {
			datas = JSON.parse(datas);
			if (datas != null) {
				$("#" + channelShort).val(datas[0].generalizeAbbreviation);
				$("#linkSite").val(datas[0].linkSite);
				$("#downloadLink").val(datas[0].channelnumber);
			}
		}
	});
	$("#ycwbk").val(provinceID);
}

function icancel() {
	window.location.href = projectName + "/channel/select.do";

}
function add(provinceID) {
	$("#sidebarAdd").html("");
	$.ajax({
		type : "post",
		url : projectName + "/channel/selectAdd.do?key=" + provinceID,
		data : {},
		success : function(resp) {
			$("#sidebarAdd").html(resp);
		},
		error : function(err) {
		}
	});
}
function update(provinceID) {
	$("#sidebarAdd").html("");
	$.ajax({
		type : "post",
		url : projectName + "/channel/selectUpdate.do?key=" + provinceID,
		data : {},
		success : function(resp) {
			var code = resp.code;
			var error = resp.error;
			if (code == "0000") {
				$("#sidebarAdd").html(error);
			} else {
				alert(error);
			}
		},
		error : function(err) {
		}
	});
}
